package com.cjm.one.controller.customer;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cjm.one.common.result.Result;
import com.cjm.one.model.custom.entity.CustomerBalanceRecord;
import com.cjm.one.service.CustomerBalanceRecordService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.Min;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

@RestController
@Slf4j
@Tag(name = "用户余额", description = "用户余额")
@RequestMapping("/api/customer/balance/record")
public class CustomerBalanceRecordController {
    @Resource
    private CustomerBalanceRecordService customerBalanceRecordService;

    @GetMapping("/info")
    @Operation(summary = "获取当前用户的余额")
    public Result<BigDecimal> info() {

        return customerBalanceRecordService.getCustomerBalance();
    }

    @GetMapping("/list")
    @Operation(summary="获取当前用户的余额记录列表")
    public Result<Page<CustomerBalanceRecord>> list(@Validated @Min(1) @RequestParam(value = "current",  defaultValue = "1") Integer current ,
                                                    @Validated @Min(1) @RequestParam(value = "size",  defaultValue = "10") Integer size) {
        return customerBalanceRecordService.getCustomerBalanceRecordPage(current, size);
    }

    @PostMapping("/add")
    @Operation(summary="添加余额记录")
    public Result<Boolean> add(@RequestBody CustomerBalanceRecord customerBalanceRecord) {
        return customerBalanceRecordService.addCustomerBalance(customerBalanceRecord);
    }
}
